


function appendElementForDlg(){
	var dlgStr="";
	dlgStr+='<div class="gwTypeDlg" id="fw-type-dlg">';
		dlgStr+='<div class="title">';
			dlgStr+='<span class="title-tit">公文文种</span>';
			dlgStr+='<span class="title-info">选择公文文种</span>';
		dlgStr+='</div>';
		dlgStr+='<div class="dlg-menu" id="fw-type-dlg-content">';
	    dlgStr+='</div>';
	dlgStr+='</div>';
  $("#awsui-tabs-content").append(dlgStr);
}
function openSelectFwTypeDlg(){
	renderFwTypeContent();
	$("#fw-type-dlg").dialog();
}

function renderFwTypeContent(){
	$("#fw-type-dlg-content").empty();
	var sid;
	if(sid==undefined){
		sid=$("#sid").val();
	}
	var deptid="1";
	var url = './jd?sid=' + sid + '&cmd=com.whccb.apps.office.document_getOfficeDocumentRecordType';
	awsui.ajax.post(url, {deptid:deptid}, function(responseObject) {
		if(responseObject['result'] == 'ok'){
			var recordTypes = responseObject["data"]['odRecordTypes'];
			  renderTypeElement(recordTypes);
		}else{
			$.simpleAlert(responseObject['msg'], responseObject['result']);
		}
	}, 'json');
	
}

function renderTypeElement(recordTypes){
	$("#fw-type-dlg-content").empty();
	var contentStr="";
	contentStr+="<div class='select-type-panel'>";
	contentStr+="<ul>";
	for (var i=0; i <recordTypes.length; i++) {
		var recordTypeInfo = recordTypes[i];
		//剔除总行督办通报
		if(recordTypeInfo["NAME"].indexOf("督办通报") >= 0){
			continue;
		}
		contentStr+="<li>";
		contentStr+="<img src='../apps/com.actionsoft.apps.gw/img/gw_type.png' width='16px' height='16px' style='padding-bottom: 3px;'>";
		contentStr+="<span class='select-type-text'  id='"+recordTypeInfo["ID"]+"' processid='"+recordTypeInfo["PROCESSDEFID"]+"'>"+recordTypeInfo["NAME"]+"</span>";
		contentStr+="</li>";
	};
	contentStr+="</ul";
	contentStr+="</div>";
    contentStr+="";
	contentStr+="";
	$("#fw-type-dlg-content").append(contentStr);
	
	$(".select-type-text").click(function(){
		  var processIdVal=$(this).attr("processid");
		  var typeId=$(this).attr("id");
	      var processId="obj_a15f67f0bc2248b1a14598ac6425d938";
			if(processIdVal!=undefined && processIdVal!=''){
				processId=processIdVal;
			}
		openFwForm(processId,typeId);
		$("#fw-type-dlg").dialog("close");
	});
}

function openFwForm(processId,typeId){
	var sid;
	if(sid==undefined){
		sid=$("#sid").val();
	}
	var url = "./w?sid="+sid + "&cmd=com.whccb.apps.office.document.gw_open_fw_form" + "&processId=" + processId + "&typeId=" + typeId;
	window.open(url);
}


/**
*打开rowData1
*/
function openData1(rowData1,rowData2){
		rowData1.style.position="inherit";
		rowData1.style.visibility="";

		rowData2.style.height="0px";
		zwdiv.style.height="0px";
		rowData2.style.visibility="hidden";
		
		

		Tab1.className="tab1";
		Tab2.className="tab2";
}
/**
*打开rowData2
*/
function openData2(rowData1,rowData2){
	rowData2.style.position="inherit";
	rowData2.style.visibility="";
	rowData2.style.height="0px";
	zwdiv.style.height="0px";
	
	//Tab1.className="tab2";
	//Tab2.className="tab1";
	try{
		WebOffice.FullSize(true);
	}catch(e){}
    
	
}


function btclickBefore(buttonName){
	
	if("公文套红" == buttonName){
		var NUM = $("input[name=NUM]").val();
		if(NUM == null || NUM == '' || NUM == 0 || NUM == '0' || NUM == 'undefined' ){
			$.simpleAlert("请先通过<申请文号>按钮确定文号", "error");
			return false;
		}
	}
	if("申请文号" == buttonName){
		var NUM = $("input[name=NUM]").val();
		if(NUM != null && NUM != '' && NUM != 0 && NUM != '0' && NUM != 'undefined' ){
			$.simpleAlert("当前发文已有文号，如需修改，请通过<修改文号>按钮来完成", "error");
			return false;
		}
	}
	if("修改文号" == buttonName){
		var NUM = $("input[name=NUM]").val();
		if(NUM == null || NUM == '' || NUM == 0 || NUM == '0' || NUM == 'undefined' ){
			$.simpleAlert("请先通过<申请文号>按钮确定文号", "error");
			return false;
		}
		$("input[name=oldFileNum]").val(NUM);
		showModifyFileNumDlg();
	}
	
	if("收回流程" == buttonName){
		if(confirm("该操作会收回流程，并删除已发布的文件，是否确认？")){
			showCancelDlg();
			return true;
		}
	    return false;
	}
	
	if("增加分支" == buttonName){
	    showAddDlg();
	}
	if("删除分支" == buttonName){
	    showDelDlg();
	}
	if("增加或删除分支" == buttonName){
	    if(confirm("该操作会激活'代录董事长意见'节点，并在文书岗生成待办任务，是否确认？")){
			showLeaderOptionDlg();
			return true;
		}
	}
	
}


function showLeaderOptionDlg() {
    var pointTaskDefid = "obj_c747c1bc85600001462310001af01c88";
    var cancelreason ="代录董事长批示意见";	
	awsui.ajax.request({
				url : "./jd",
				method : "POST",
				data : {sid:sid, 
				reason:cancelreason,
				bindid:bindid,
				pointTaskDefid:pointTaskDefid,
				cmd:"com.whccb.apps.office.document_to_leaderoption_task"
			},
			ok : function(r) {
				alert(r.data);
			},
			err:function(r){
								    
			}
	});
}

function showModifyFileNumDlg() {
    
    var recordTypeId = $("input[name=RECORDTYPEID]").val(); 	
	var year = $("input[name=YEAR]").val(); 	
	$("#modifyFileNumDlg").dialog({
		"buttons":[{text:'确定',cls:"red",handler:function(){
							var newFileNum = $("input[name=newFileNum]").val();
							//非空校验
							if (newFileNum == "") {
								$.simpleAlert("[拟使用文号]不允许为空","info");
								return;
							}
							awsui.ajax.request({
							    url : "./jd",
							    method : "POST",
							    data : {sid:sid, 
							    		bindid:bindid,
							    		boName:"BO_WHBK_OD_DRAFT",
										recordTypeId:recordTypeId,
										year:year,
										flag:"0",//发文
										fileNum:newFileNum,
										cmd:"com.whccb.apps.office.document.modify_file_num"
							    	   },
							    ok : function(r) {
									debugger;
									var fileNum = r.data.fileNum;
									var odFileNum = r.data.odFileNum;
		                            $("input[name=FILENUM]").val(odFileNum);
									$("input[name=NUM]").val(fileNum);
		                            $("#NUM_Readonly").html(fileNum);
									alert("新文号更新成功");
									$("#modifyFileNumDlg").dialog("close");
							    },
							    err:function(r){
									debugger;
							    }
							});
							
						}},
						{text:'取消',handler:function(){
							$("#modifyFileNumDlg").dialog("close");
						}}]
	});
}


function showCancelDlg() {
    var pointTaskDefid = userTaskDefId;	
	$("#cancelDlg").dialog({
		"buttons":[{text:'确定',cls:"red",handler:function(){
			var cancelreason = $("input[name=cancelreason]").val();
		    //非空校验
			if (cancelreason == "") {
				$.simpleAlert("[收回原因]不允许为空","info");
				return;
			}
			awsui.ajax.request({
				url : "./jd",
				method : "POST",
				data : {sid:sid, 
				reason:cancelreason,
				bindid:bindid,
				pointTaskDefid:pointTaskDefid,
				cmd:"com.whccb.apps.office.document_backprocess_task"
			},
			ok : function(r) {
				alert(r.data);
				$("#cancelDlg").dialog("close");
			},
			err:function(r){
								    
			}
	        });
							
	        }},
	        {text:'取消',handler:function(){
				$("#cancelDlg").dialog("close");
			}}]
	});
}



function btclickSuccess(buttonName,response){
	if("申请文号" == buttonName){
		var fileNum = response.data.fileNum;
		var odFileNum = response.data.odFileNum;
		$("input[name=FILENUM]").val(odFileNum);
		$("input[name=NUM]").val(fileNum);
		$("#NUM_Readonly").html(fileNum);
		alert("文号申请成功，为"+fileNum+"号");
	}
}

function btclickFailure(buttonName,response){
	if("申请文号" == buttonName){
		alert("参数有误，BO未找到");
	}
}


function showAddDlg() {	

	$("#addDlg").dialog({
		"buttons":[{text:'确定',cls:"blue",handler:function(){
							var adddouserid = $("input[name=adddouserid]").val();
							//非空校验
							if (adddouserid == "") {
								$.simpleAlert("[用户帐号]不允许为空","info");
								return;
							}
							awsui.ajax.request({
							    url : "./jd",
							    method : "POST",
							    data : {sid:sid, 
							    		parentProcessinstid:bindid,
							    		parentTaskDefid:"obj_c747c1b955a00001803d9ee07ea01ccc",
										useridstr:adddouserid,
										cmd:"com.whccb.apps.office.document.sw_addsubpro"
							    	   },
							    ok : function(r) {
							    	alert(r.data.backMessage);
									$("#addDlg").dialog("close");
							    },
							    err:function(r){
								    
							    }
							});
							
						}},
						{text:'取消',handler:function(){
							$("#addDlg").dialog("close");
						}}]
	});
}


function showDelDlg() {	
	$("#delDlg").dialog({
		"buttons":[{text:'确定',cls:"red",handler:function(){
							var deldouserid = $("input[name=deldouserid]").val();
							//非空校验
							if (deldouserid == "") {
								$.simpleAlert("[用户帐号]不允许为空","info");
								return;
							}
							awsui.ajax.request({
							    url : "./jd",
							    method : "POST",
							    data : {sid:sid, 
							    		parentProcessinstid:bindid,
							    		parentTaskDefid:"obj_c747c1b955a00001803d9ee07ea01ccc",
										useridstr:deldouserid,
										cmd:"com.whccb.apps.office.document.sw_delsubpro"
							    	   },
							    ok : function(r) {
							    	alert(r.data.backMessage);
									$("#delDlg").dialog("close");
							    },
							    err:function(r){
								    
							    }
							});
							
						}},
						{text:'取消',handler:function(){
							$("#delDlg").dialog("close");
						}}]
	});
}




